package com.study.utils;

import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @desc:
 * @author: panxiyi
 * @date: 2023/4/15 12:17 上午
 */
public enum Logs {

    common("common"),
    ;

    private org.slf4j.Logger logger;

    private String category;


    Logs(String category) {
        this.category = category;
        this.logger = LoggerFactory.getLogger(category);
    }

    public void error(Throwable t, Pair<?, ?>... pairs) {
        Map<Object, Object> params = new HashMap<>(pairs.length);
        for (Pair<?, ?> p : pairs) {
            if (p != null) {
                params.put(p.getFirst(), p.getSecond());
            }
        }
        this.logger.error("{}", JackJsonUtil.toJSONString(params));
    }

    /**
     * error
     *
     * @param pairs
     */
    public void info(Pair<?, ?>... pairs) {
        Map<Object, Object> params = new HashMap<>(pairs.length);
        for (Pair<?, ?> p : pairs) {
            if (p != null) {
                params.put(p.getFirst(), p.getSecond());
            }
        }
        this.logger.info("{}", JackJsonUtil.toJSONString(params));
    }

    public void info(Throwable t, Pair<?, ?>... pairs) {
        Map<Object, Object> params = new HashMap<>(pairs.length);
//        if (!StringUtils.equals(this.category, ACCESS)) {
//            params.put("level", "error");
//        }
//        params.put("category", this.category);
//        params.put("requestId", RequestContext.getRequestId());
//        params.put("threadName", getThreadName());
//        params.put("traceId", TraceIdUtil.getTraceId());
        for (Pair<?, ?> p : pairs) {
            if (p != null) {
                params.put(p.getFirst(), p.getSecond());
            }
        }
        this.logger.info("{}", JackJsonUtil.toJSONString(params));
    }

    /**
     * error
     *
     * @param pairs
     */
    public void error(Pair<?, ?>... pairs) {
        Map<Object, Object> params = new HashMap<>(pairs.length);
//        if (!StringUtils.equals(this.category, ACCESS)) {
//            params.put("level", "error");
//        }
//        params.put("category", this.category);
//        params.put("requestId", RequestContext.getRequestId());
//        params.put("threadName", getThreadName());
//        params.put("traceId", TraceIdUtil.getTraceId());
        for (Pair<?, ?> p : pairs) {
            if (p != null) {
                params.put(p.getFirst(), p.getSecond());
            }
        }
        this.logger.error("{}", JackJsonUtil.toJSONString(params));
    }

}
